package fr.gest4team.app.pilotage.dao;

import java.util.List;

import fr.gest4team.app.pilotage.dao.abstrait.AbstractVersionDao;
import fr.gest4team.app.pilotage.dao.interfaces.IVersionDao;
import fr.gest4team.app.pilotage.dto.Version;

/**
 * Dao modifiable
 * 
 * @see fr.gest4team.app.pilotage.dto.Version
 */
public class VersionDao extends AbstractVersionDao implements IVersionDao {

    /**
     * @author brug
     * @return retourne la liste des Versions.
     */
    public List<String> chargerListeVersion() {
        final String hql = "select nom from Version";
        return (List) executeHqlQuery(hql);
    }

    public List<Version> chargerVersions() {
        final String hql = "from Version";
        return executeHqlQuery(hql);
    }

    public void deleteVersion(final String version) {
        final String hql = "delete Version as a where a.nom=?";
        getHibernateTemplate().bulkUpdate(hql, version);

    }

    public Version findByNom(final String version) {
        final String hql = "from Version as v where v.nom= ?";
        final List<Version> versions = executeHqlQuery(hql, new Object[] { version });
        return (versions.size() == 1) ? versions.get(0) : null;
    }

    public String findNomById(final Integer version) {
        final String hql = "select nom from Version as v where v.idVersion= ?";
        final List<String> versions = (List) executeHqlQuery(hql, new Object[] { version });
        return (versions.size() == 1) ? versions.get(0) : null;
    }
}